home *** CD-ROM | disk | FTP | other *** search
- <%@ Language=VBScript%>
- <HTML>
- <HEAD>
- <META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
- <TITLE>Employees</TITLE>
-
- <%
- Dim oConn ' ADO connection object.
- Dim oRs ' Employee recordset object.
- Dim oRsPhone ' Emp phone recordset object.
- Dim strSql ' SQL string.
-
- ' Establish a connection to the database.
- Set oConn = Server.CreateObject("ADODB.Connection")
- Call oConn.Open( "DSN=Employees;UID=Admin;PWD=;" )
-
- ' Open a recordset containing all of the employees.
- Set oRs = Server.CreateObject("ADODB.Recordset")
- strSql = "SELECT * FROM employees ORDER BY lastname, firstname"
- Call oRs.Open( strSql, oConn )
-
-
- Response.Write( "<XML ID=employees>" & vbCrLf )
- Response.Write( "<employees>" & vbCrLf)
-
- ' Iterate through all of the employees in
- ' the database and generate the appropriate
- ' XML document that contains their information.
- While Not oRs.EOF
-
- ' Display all of the employee information
- ' that is in the employee table.
- Response.Write( "<employee>" & vbCrLf )
- Response.Write( " <name>" & vbCrLf )
- Response.Write( " <first>" & oRs("firstname") & "</first>" & vbCrLf )
- Response.Write( " <last>" & oRs("lastname") & "</last>" & vbCrLf )
- Response.Write( " </name>" & vbCrLf )
- Response.Write( " <position>" & oRs("position") & "</position>" & vbCrLf )
- Response.Write( " <phone>" & vbCrLf )
-
- ' Get the phone numbers for this employee
- ' and generate the appropriate tags and content.
- Set oRsPhones = Server.CreateObject("ADODB.Recordset")
- strSql = "SELECT * FROM phonenumbers" ' WHERE phonetype = 'main' AND id = '" & oRs("id") & "'"
- Call oRsPhones.Open( strSql, oConn )
-
- While Not oRsPhones.EOF
- ' Generate the tag containing the appropriate
- ' phone information (type and number)
- Response.Write( " <" & oRsPhones("phonetype") & ">" )
- Response.Write( oRsPhones("phonenumber") )
- Response.Write( "</" & oRsPhones("phonetype") & ">" & vbCrLf )
- oRsPhones.MoveNext
- Wend
-
- Response.Write( " </phone>" & vbCrLf )
- Response.Write( "</employee>" & vbCrLf & vbCrLf )
- oRs.MoveNext
- Wend
-
- oRsPhones.Close
- oRs.Close
- oConn.Close
-
- Response.Write( "</employees>" & vbCrLf )
- Response.Write( "</XML>" & vbCrLf & vbCrLf )
- %>
-
- <SCRIPT LANGUAGE=javascript>
- <!--
- var xmlDoc;
-
- function button1_onclick()
- {
- var xmlEmp = employees.documentElement.childNodes.item( select1.selectedIndex );
- var xmlPos = xmlEmp.childNodes.item( 1 );
- var xmlPhone = xmlEmp.childNodes.item( 2 );
-
- position.innerText = xmlPos.text;
- phone.innerText = xmlPhone.childNodes.item(0).text;
- }
- //-->
- </SCRIPT>
- </HEAD>
-
-
- <BODY>
-
-
- <!-- Put the employee names within
- the combo box.
- -->
- <H2>Select an employee</H2>
- <SELECT id=select1 name=select1>
- <SCRIPT LANGUAGE=javascript>
- <!--
- var xmlRoot = employees.documentElement;
- var intTotal = xmlRoot.childNodes.length;
- var xmlEmp;
- var intCount;
-
- for ( intCount = 0;
- intCount < intTotal;
- intCount++ )
- {
- xmlEmp = xmlRoot.childNodes.item( intCount );
- document.write( "<OPTION>" );
- document.write( xmlEmp.childNodes.item( 0 ).text );
- document.write( "</OPTION>" );
- }
- //-->
- </SCRIPT>
- </SELECT>
-
- <INPUT type="button" value="Go get it!" id=button1 name=button1 LANGUAGE=javascript onclick="return button1_onclick()">
-
- <P>
- <TABLE WIDTH=100%>
- <TR><TD WIDTH=10%><B>Position:</B>
- <TD><SPAN ID=position></SPAN>
- <TR><TD><B>Phone:</B>
- <TD><SPAN ID=phone></SPAN>
- </TABLE>
-
- </BODY>
- </HTML>
-